package com.example.wechatlistview.events.strategys;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.wechatlistview.R;
import com.example.wechatlistview.events.controllers.ClickController;
import com.example.wechatlistview.pages.pg_moments;
import com.example.wechatlistview.pages.pg_scan;
import com.example.wechatlistview.resmanager.DataSource;
import com.example.wechatlistview.tools.CustomTools;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.interfaces.OnSelectListener;

/**
 * @author CVLocke 陈炜龙
 */
public class ClickStrategy {


    /**
     * 标签策略组
     */
    public enum TagStrategy {

        /**
         * 朋友圈
         */
        MOMENTS {
            @Override
            public void run(Context context, String tag) {
                Activity activity = CustomTools.getActivityFromContext(context);
                Intent intent = new Intent(activity, pg_moments.class);
                activity.startActivity(intent);
            }
        },
        /**
         * 扫一扫
         */
        SCAN {
            @Override
            public void run(Context context, String tag) {
                Activity activity = CustomTools.getActivityFromContext(context);
                Intent intent = new Intent(activity, pg_scan.class);
                activity.startActivityForResult(intent, 6624);

            }
        };


        public abstract void run(Context context, String tag);


    }


    /**
     * 按钮事件策略组
     */
    public enum BtnStratgy {
        /**
         * 返回按钮
         */
        BACK {
            @Override
            public void run(View view, @Nullable ClickController.BtnBuilder.Param param) {
                //获取当前activity
                Activity activity = CustomTools.getActivityFromView(view);
                activity.finish();
            }
        },
        /**
         * 聊天fg添加按钮
         */
        CHATS_ADD {
            @Override
            public void run(View view, @Nullable ClickController.BtnBuilder.Param param) {
                Context context = view.getContext();
                DataSource dataSource = new DataSource(context);
                new XPopup.Builder(context)
                        .atView(view)
                        .isDarkTheme(true)
                        .asAttachList(dataSource.GetStrArrayFromRes(R.array.chats_add), new int[]{
                                R.drawable.icon_bubble,
                                R.drawable.icon_addfriend,
                                R.drawable.icon_scan,
                                R.drawable.icon_payment
                        }, new OnSelectListener() {
                            @Override
                            public void onSelect(int position, String text) {
                                String tag = dataSource.GetStrArrayFromRes(R.array.tag_chats_add)[position];
                                try {
                                    ClickStrategy.TagStrategy strategy = ClickStrategy.TagStrategy.valueOf(tag);
                                    strategy.run(context, tag);
                                } catch (Exception e) {
                                    TOAST.run(view, null);
                                }
                            }
                        }, R.layout.popuview_chats_holder, R.layout.popupview_chats, Gravity.START).show();
            }
        },
        /**
         * Toast提示按钮（测试）
         */
        TOAST {
            @Override
            public void run(View view, @Nullable ClickController.BtnBuilder.Param param) {
                Toast.makeText(view.getContext(), ClickController.BtnBuilder.Param.pToast.text, ClickController.BtnBuilder.Param.pToast.time).show();
            }
        };

        public abstract void run(View view, @Nullable ClickController.BtnBuilder.Param param);

    }


}
